from django.db import models
from utils.model import BaseModel
from django.conf import settings

# Create your models here.
class Banner(BaseModel):
    title = models.CharField(max_length=16, verbose_name='标题')
    link = models.CharField(max_length=64, verbose_name='链接')
    image = models.ImageField(upload_to="banner", verbose_name='图片链接')
    info = models.CharField(max_length=32, verbose_name='轮播图简介')
    order = models.IntegerField(verbose_name='显示顺序')

    @property
    def image_url(self):
        return f"{settings.BASE_URL}/media/{self.image}"

    class Meta:
        db_table = 'db_banner'
        verbose_name_plural = '轮播图表'

    def __str__(self):
        return self.title


class Recommend(BaseModel):
    category_choice=[(1,"电影"),(2,"电视剧"),(3,"综艺"),(4,"动漫"),(5,"纪录片"),(6,"短片")]
    title = models.CharField(max_length=64, verbose_name="视频标题")
    score = models.DecimalField(max_digits=5, decimal_places=1, verbose_name="视频评分", default=0)
    image = models.ImageField(upload_to="home/", max_length=255, verbose_name="视频封面图片", blank=True, null=True)
    heat = models.IntegerField(default=0, verbose_name="视频热度")
    order = models.IntegerField(default=0, verbose_name="显示顺序")
    info = models.CharField(max_length=32,verbose_name='简介')
    is_free = models.BooleanField(default=1, verbose_name="是否免费")
    category_id =  models.IntegerField(choices=category_choice, verbose_name="视频类别")
    video_id = models.IntegerField(verbose_name="视频主键")
    status = models.CharField(max_length=16, verbose_name="视频状态")

    @property
    def image_url(self):
        return f"{settings.BASE_URL}/media/{self.image}"

    class Meta:
        db_table = 'db_recommend'
        verbose_name_plural = '视频推荐表'

    def __str__(self):
        return self.title
